<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="日期" prop="ftdate">
        <el-date-picker clearable
          v-model="queryParams.ftdate"
          type="month"
          value-format="yyyy-MM-dd"
          @input="handleMonthChange"
          placeholder="请选择日期">
        </el-date-picker>
      </el-form-item><el-form-item  :gutter="10" class="mb3"   v-show="jyjcsh.flag ==3"> 
    
    {{JyjcShDatas.createBy}}{{JyjcShDatas.createTime}}{{JyjcShDatas.shName}}  
   </el-form-item>
   <div>
    <el-collapse v-model="activeNames">
      <el-collapse-item title="审核记录" name="1">
        <div v-for="item in JyjcShDataslist" :key="item.index" v-show="JyjcShDataslist != null">
          <el-form-item class="mb3">
            <span class="ml-10">{{ item.createBy }}</span>
            <span class="ml-10">{{ item.createTime }}</span>
            <span class="ml-10">{{ item.shName }}</span>
          </el-form-item>
        </div>
      </el-collapse-item>
    </el-collapse>
  </div>
    </el-form>
    <el-row :gutter="10" class="mb8"  style="text-align: center;font-size: 50px;"> 
     收入成本汇总表(财务负责人审核)
  </el-row>
  <el-row type="flex" justify="end">
    <el-col :span="3" style="font-size: 50px; color: red;">
      内部资料
    </el-col>
  </el-row>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
        v-if=" total>0 &&jyjcsh.flag ==2 "  
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="sh" 
        >审核</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
        v-if="total>0 && jyjcsh.flag ==2"  
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="ht" 
        >驳回</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
        >导出</el-button>
      </el-col>
       <!-- <el-col :span="1.5"> <el-button v-print="printObj">打印表格</el-button></el-col> -->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="JyjcSharingExpensesSumList" id="printContent"  @selection-change="handleSelectionChange" height="700"  >
      <el-table-column type="selection" width="30" align="center" />
      <el-table-column label="年份" fixed  width="55" align="center" prop="year" />
      <el-table-column label="月份"  fixed  width="55" align="center" prop="yf" />
      <!-- <el-table-column label="部门" align="center" prop="deptname" />
      <el-table-column label="部门编码" align="center" prop="deptcode" /> -->
       <el-table-column label="经济科目" fixed    align="center" :min-width="200" prop="jjkm" /> 
      <!-- <el-table-column label="包含的费用" align="center" prop="expenseType" /> -->
      <el-table-column label="总合计"  fixed  width="120"  align="center" prop="zthj" />
      <el-table-column label="办公室(党群工作部)" width="100"   align="center" prop="bgs" />
      <el-table-column label="人力资源部" width="100"  align="center" prop="rlzy" />
      <el-table-column label="财务内审部" width="100"  align="center" prop="cw" />
      <el-table-column label="市场拓展部(业务协作部)" width="100"  align="center" prop="sctz" />
      <el-table-column label="质量管理部"  width="100" align="center" prop="zlgl" />
      <el-table-column label="设备管理部" width="100"  align="center" prop="sbgl" />
      <el-table-column label="科技规划研究所" width="100"   align="center" prop="kjghyjs" />
      <!-- <el-table-column label="专业所合计" width="100"  align="center" prop="zyshj" /> -->
      <el-table-column label="计量科学研究所" width="100"  align="center" prop="jls" />
      <el-table-column label="标准研究所" width="100"  align="center" prop="bzs" />
      <el-table-column label="特种设备检验技术研究所" width="100"   align="center" prop="tzs" />
      <el-table-column label="产品质量检验技术研究所" width="100"   align="center" prop="cps" />
      <el-table-column label="纤维质量监测研究所" width="100"  align="center" prop="xws" />
      <el-table-column label="食品与粮食检验技术研究所" width="100"  align="center" prop="sps" />
      <el-table-column label="药品检验技术研究所" width="100"  align="center" prop="yps" />
      <el-table-column label="医疗器械检验技术研究所" width="100"  align="center" prop="yls" />
      <el-table-column label="农产品与农药土壤肥料检验技术研究所"  width="100"  align="center" prop="ncp" />
      <el-table-column label="畜牧与水产品检验技术研究所" width="100"  align="center" prop="xms" />
      <el-table-column label="能源产品检验技术研究所" width="100"  align="center" prop="nys" />
      <el-table-column label="度量衡检定所" width="100"  align="center" prop="dls" />
      <el-table-column label="计算合计" width="100"   align="center" prop="lbyshj" />
      <el-table-column label="职能部门分摊" width="100"   align="center" :show-overflow-tooltip="true" prop="mark1" />
      <el-table-column label="专业所独立行使事项" width="100"  align="center"  :show-overflow-tooltip="true" prop="mark2" />
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listJyjcSharingExpensesSum, getJyjcSharingExpensesSum, delJyjcSharingExpensesSum, addJyjcSharingExpensesSum, updateJyjcSharingExpensesSum,alllSumlist } from "@/api/system/JyjcSharingExpensesSum"
import { UpdateFlag,UpdateFlagStatistics } from "@/api/system/expenses"
import { getjyjcSh } from "@/api/system/jyjcSh"
import { getJyjcShDatasLast ,getJyjcShDatasList } from "@/api/system/jyjcShDatas"
export default {
  name: "JyjcSharingExpensesSum",
  data() {
    return {
      activeNames: ['0'], // 默认展开
      JyjcShDataslist: null,
      JyjcShDatasQuery: {
        shId: ""
       
      },
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 财务收入支出统计表格数据
      JyjcSharingExpensesSumList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 50,
        ftdate: "",
        year: null,
        yf: null,
        deptname: null,
        deptcode: null,
        jjkm: null,
        expenseType: null,
        mark1: null,
        mark2: null,
        orderNum: null,
        flag:"2"
      },
      updateflag:{
        year: "",
        yf: "",
        deptcode: "",
        flag:"",
        //动作
        expenseType:"",
        //审批人
        economicKm:""
      },  
      jyjcsh: {
        yearyf: "",
        type: 'statistics',
        flag: "",
        createBy:""
      },
      JyjcShDatas: {
        createBy: "",
        createTime: "",
        shName: ""
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    }
  },
  created() {
    this.queryParams.ftdate= this.getCurrentMonth();
        this.jyjcsh.flag="";
    this.handleMonthChange();

  },
  methods: {
    /** 查询财务收入支出统计列表 */
    getList() {
      this.loading = true
      alllSumlist(this.queryParams).then(response => {
        this.JyjcSharingExpensesSumList = response.rows
        this.total = response.total
        if(response.total>0){
          this.getjyjcSh()
        }
        this.loading = false
      })
    },
    getjyjcSh() {
      
      getjyjcSh(this.jyjcsh).then(response => {
        
        this.jyjcsh.flag=response.data.flag
        this.jyjcsh.createBy=response.data.createBy
        this.jyjcsh.createTime=response.data.createTime
     
        this.getJyjcShDatasLast(response.data.id)
      })
    },
    getJyjcShDatasLast(id){
    
    getJyjcShDatasLast(id).then(response => {

      this.JyjcShDatas.shName=response.data.shName
      this.JyjcShDatas.createBy=response.data.createBy
      this.JyjcShDatas.createTime=response.data.createTime
    })
    this.getJyjcShDatasList(id);
  }, 
  getJyjcShDatasList(id){

    this.JyjcShDatasQuery.shId=id
    getJyjcShDatasList(this.JyjcShDatasQuery).then(response => {
   console.info(response.rows);
      this.JyjcShDataslist=response.rows
      
    })
  },
    //打印按钮
    printObj: {
        id: "printContent", // 要打印的 DOM ID
        popTitle: "数据打印", // 打印标题
      },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        year: null,
        yf: null,
        deptname: null,
        deptcode: null,
        jjkm: null,
        expenseType: null,
        zthj: null,
        lbyshj: null,
        bgs: null,
        rlzy: null,
        cw: null,
        sctz: null,
        zlgl: null,
        sbgl: null,
        kjghyjs: null,
        zyshj: null,
        jls: null,
        bzs: null,
        tzs: null,
        cps: null,
        xws: null,
        sps: null,
        yps: null,
        yls: null,
        ncp: null,
        xms: null,
        nys: null,
        dls: null,
        mark1: null,
        mark2: null,
        orderNum: null
      }
      this.resetForm("form")
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm")
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.year)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.open = true
      this.title = "添加财务收入支出统计"
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      const year = row.year || this.ids
      getJyjcSharingExpensesSum(year).then(response => {
        this.form = response.data
        this.open = true
        this.title = "修改财务收入支出统计"
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.year != null) {
            updateJyjcSharingExpensesSum(this.form).then(response => {
              this.$modal.msgSuccess("修改成功")
              this.open = false
              this.getList()
            })
          } else {
            addJyjcSharingExpensesSum(this.form).then(response => {
              this.$modal.msgSuccess("新增成功")
              this.open = false
              this.getList()
            })
          }
        }
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const years = row.year || this.ids
      this.$modal.confirm('是否确认删除财务收入支出统计编号为"' + years + '"的数据项？').then(function() {
        return delJyjcSharingExpensesSum(years)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess("删除成功")
      }).catch(() => {})
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/JyjcSharingExpensesSum/export', {
        ...this.queryParams
      }, `收入成本汇总表_${new Date().getTime()}.xlsx`)
    }, 
    handleMonthChange(){
      this.queryParams.pageNum = 1;
      const [y, m,d] = this.queryParams.ftdate.split('-');
      this.queryParams.year=y;
      this.queryParams.yf=m;
      this.jyjcsh.yearyf= y+"-"+m;
      this.jyjcsh.flag="";
      this.getList();
      this.getjyjcSh();
    },
    getCurrentMonth() {
      const now = new Date()
      const year = now.getFullYear()
      const month = String(now.getMonth() + 1).padStart(2, '0')
      return `${year}-${month}`
    },
    sh() {
      this.jyjcsh.flag='3';
      this.updateflag.flag='3';
      this.updateflag.deptcode=this.queryParams.deptcode;
      this.updateflag.year=this.queryParams.year;
      this.updateflag.yf=this.queryParams.yf;
      this.updateflag.expenseType='审核';
      this.updateflag.economicKm='张军强 ';
      UpdateFlagStatistics(this.updateflag).then(
        this.$modal.msgSuccess("审核成功")
      );  
       this.getjyjcSh();
    },
      ht() {
      this.jyjcsh.flag='1';
      this.updateflag.flag='1';
      this.updateflag.deptcode=this.queryParams.deptcode;
      this.updateflag.year=this.queryParams.year;
      this.updateflag.yf=this.queryParams.yf;
      this.updateflag.expenseType='驳回';
      this.updateflag.economicKm='张军强 ';
      UpdateFlagStatistics(this.updateflag).then(
        this.$modal.msgSuccess("驳回成功")
      );
      this.getjyjcSh();
}
  }
}
</script>
